using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Hr.Attendance;


namespace HengTong.ViewModel.Hr.SysAttendanceRawRecordVms
{
    public partial class SysAttendanceRawRecordListVm : BaseListVm<SysAttendanceRawRecordView, SysAttendanceRawRecordSearcher>
    {

        protected override IEnumerable<IGridColumn<SysAttendanceRawRecordView>> InitGridHeader()
        {
            return new List<GridColumn<SysAttendanceRawRecordView>>{
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.StaffNo),
                this.MakeGridHeader(x => x.PunchTime),
                this.MakeGridHeader(x => x.DeviceId),
                this.MakeGridHeader(x => x.DeviceName),
                this.MakeGridHeader(x => x.Location),
                this.MakeGridHeader(x => x.Longitude),
                this.MakeGridHeader(x => x.Latitude),
                this.MakeGridHeader(x => x.PunchType),
                this.MakeGridHeader(x => x.RecognitionType),
                this.MakeGridHeader(x => x.RawData),
                this.MakeGridHeader(x => x.ProcessStatus),
                this.MakeGridHeader(x => x.ProcessTime),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysAttendanceRawRecordView> GetSearchQuery()
        {
            var query = DC.Set<SysAttendanceRawRecord>()
                .CheckEqual(Searcher.PersonId, x=>x.PersonId)
                .CheckEqual(Searcher.StaffNo, x=>x.StaffNo)
                .CheckBetween(Searcher.PunchTime?.GetStartTime(), Searcher.PunchTime?.GetEndTime(), x => x.PunchTime, includeMax: false)
                .CheckContain(Searcher.DeviceId, x=>x.DeviceId)
                .CheckContain(Searcher.DeviceName, x=>x.DeviceName)
                .CheckContain(Searcher.Location, x=>x.Location)
                .CheckEqual(Searcher.Longitude, x=>x.Longitude)
                .CheckEqual(Searcher.Latitude, x=>x.Latitude)
                .CheckContain(Searcher.PunchType, x=>x.PunchType)
                .CheckContain(Searcher.RecognitionType, x=>x.RecognitionType)
                .CheckContain(Searcher.RawData, x=>x.RawData)
                .CheckContain(Searcher.ProcessStatus, x=>x.ProcessStatus)
                .CheckBetween(Searcher.ProcessTime?.GetStartTime(), Searcher.ProcessTime?.GetEndTime(), x => x.ProcessTime, includeMax: false)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .Select(x => new SysAttendanceRawRecordView
                {
				    ID = x.ID,
                    PersonName = x.Person.Name,
                    StaffNo = x.StaffNo,
                    PunchTime = x.PunchTime,
                    DeviceId = x.DeviceId,
                    DeviceName = x.DeviceName,
                    Location = x.Location,
                    Longitude = x.Longitude,
                    Latitude = x.Latitude,
                    PunchType = x.PunchType,
                    RecognitionType = x.RecognitionType,
                    RawData = x.RawData,
                    ProcessStatus = x.ProcessStatus,
                    ProcessTime = x.ProcessTime,
                    Remark = x.Remark,
                })
                .OrderByDescending(x => x.PunchTime);
            return query;
        }
    }

    public class SysAttendanceRawRecordView : SysAttendanceRawRecord{
        [Display(Name = "姓名")]
        public String PersonName { get; set; }

    }
}
